package com.deng.mina.common.protocol;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

import java.nio.charset.Charset;

/**
 * @Project
 * @Module
 * @JDK_Vserion 1.8
 * @Author DengLibin
 * @Email dlb@smarthse.cn
 * @Desc 编解码工厂
 * @since 2019/9/18 0018 11:35
 */
public class ProtocolFactory implements ProtocolCodecFactory {
    private  com.deng.mina.common.protocol.ProtocolDecoder decoder;
    private  com.deng.mina.common.protocol.ProtocolEncoder encoder;
    public ProtocolFactory(Charset charset){
        encoder = new com.deng.mina.common.protocol.ProtocolEncoder(charset);
        decoder = new com.deng.mina.common.protocol.ProtocolDecoder(charset);
    }

    /**
     * 获取编码器
     * @param session
     * @return
     * @throws Exception
     */
    @Override
    public ProtocolEncoder getEncoder(IoSession session) throws Exception {
        return encoder;
    }

    /**
     * 获取解码器
     * @param session
     * @return
     * @throws Exception
     */
    @Override
    public ProtocolDecoder getDecoder(IoSession session) throws Exception {
        return decoder;
    }
}
